<!DOCTYPE html>
<html>
<head>
    <title>随机数求和</title>
</head>

<body>
  <button onclick="sum()">N 个随机 4 位整数/和</button>
 <script>
    function sum() {
      let n = parseInt(prompt("输入 n："));
      let total = 0;
      document.write(n+"个随机4个整数是：");
      for (let i = 0; i < n; i++) {
        let num= Math.floor(Math.random() * 9000) + 1000;
        total += num;
       document.write(num+'&nbsp');
      }
    document.write("<br>"+n+"个随机4位整数的和是"+total);
    }
  </script>
</body></html>
